package com.yanqu.road.server.cmd.activity.xingyoushanshui.cross;

import com.yanqu.road.entity.activity.youxing.config.XingYouConfig;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.shanshui.XingYouShanShuiMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = Protocol.S_XING_YOU_SHAN_SHUI_JOINT_OPERATION_FROM_CROSS,desc = "协战-跨服回包")
public class ShanShuiJointOperationFromCrossCmd  extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        XingYouShanShuiProto.ShanShuiJointOperationRsp rsp = XingYouShanShuiProto.ShanShuiJointOperationRsp.parseFrom(packet.getBytes());
        XingYouConfig config = XingYouShanShuiMgr.getConfig();
        if(player != null && config != null){
            if(rsp.hasReward() && !StringUtils.isNullOrEmpty(rsp.getReward())) {
                Property property = PropertyHelper.parseStringToProperty(rsp.getReward());
                property.removeProperty(config.getSHANSHUI_SILVER_COIN_ID());
                if(!property.isNothing()){
                    player.getModule(CurrencyModule.class).addCurrency(property, eLogMoneyType.XingYouShanShuiActivity, eLogMoneyType.XingYouShanShuiHelpReward);
                }
            }
            player.sendPacket(Protocol.U_XING_YOU_SHAN_SHUI_JOINT_OPERATION, rsp.toBuilder());
        }else {

        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
